package com.zhw.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zhw.mapper.EmpMapper;
import com.zhw.pojo.Emp;
import com.zhw.pojo.PageBean;
import com.zhw.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    EmpMapper em;

/*    @Override
    public PageBean getAll(Integer page,Integer pageSize) {
//  处理持久层查询到的员工信息以及总数据量并封装返回
        int start=(page-1)*2;
        List<Emp> list=em.getList(start,pageSize);
        Integer count=em.getCount();
        PageBean pb=new PageBean();
        pb.setTotal(count);
        pb.setRows(list);
        return pb;

    }*/

    @Override
    public PageBean getAll(Integer page, Integer pageSize, String name, Integer gender, LocalDate begin, LocalDate end) {
//  处理持久层查询到的员工信息以及总数据量并封装返回
        PageHelper.startPage(page,pageSize);
        List<Emp> list = em.selectAll(name,gender,begin,end);
        Page<Emp> p= (Page<Emp>) list;


        PageBean pb=new PageBean(p.getTotal(),p.getResult());

        return pb;

    }

    @Override
    public void delete(int[] ids) {
        em.delete(ids);
    }

    @Override
    public void insert(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        em.insert(emp);
    }

    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        em.update(emp);
    }

    @Override
    public Emp selectById(Integer id) {
        Emp emp=em.selectById(id);
        return emp;
    }

    @Override
    public Emp login(Emp emp) {
        return em.Check(emp);
    }
}
